package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
@Autowired
private  TbClueTrackRecordMapper tbClueTrackRecordMapper;
@Autowired
private TbClueMapper tbClueMapper;
    @Override
    @Transactional
    public String add(ClueTrackRecordVo tbClueTrackRecord) {
        TbClueTrackRecord tbClueTrackRecord1=new TbClueTrackRecord();
        tbClueTrackRecord1.setClueId(tbClueTrackRecord.getClueId());
        tbClueTrackRecord1.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord1.setSubject(tbClueTrackRecord.getSubject());
        tbClueTrackRecord1.setRecord(tbClueTrackRecord.getRecord());
        tbClueTrackRecord1.setLevel(tbClueTrackRecord.getLevel());
        tbClueTrackRecord1.setCreateTime(DateUtils.getNowDate());
        tbClueTrackRecord1.setType(tbClueTrackRecord.getType());
        tbClueTrackRecord1.setFalseReason(tbClueTrackRecord.getFalseReason());
        tbClueTrackRecord1.setNextTime(tbClueTrackRecord.getNextTime());
        tbClueTrackRecordMapper.save(tbClueTrackRecord1);

        TbClue tbClue = tbClueMapper.selectTbClueById(tbClueTrackRecord.getClueId());
        tbClue.setName(tbClueTrackRecord.getName());
        tbClue.setSex(tbClueTrackRecord.getSex());
        tbClue.setAge(tbClueTrackRecord.getAge());
        tbClue.setWeixin(tbClueTrackRecord.getWeixin());
        tbClue.setQq(tbClueTrackRecord.getQq());
        tbClue.setLevel(tbClueTrackRecord.getLevel());
        tbClue.setSubject(tbClueTrackRecord.getSubject());
        tbClueMapper.updateTbClue(tbClue);
        return "添加成功";
    }

    @Override
    public List<TbClueTrackRecord> getList(Long clueId) {
        List<TbClueTrackRecord> tbClueTrackRecord = tbClueTrackRecordMapper.getTbClueTrackRecord(clueId);

        return tbClueTrackRecord;
    }
}
